--{-# LANGUAGE TypeOperators, FlexibleContexts, TypeFamilies #-}
{-# LANGUAGE TypeFamilies, FlexibleContexts #-}
{- |
Module      :  Loader.InputFile
Description :  <optional short text displayed on contents page>
Copyright   :  (c) Sergey Sichevskiy 2013
License     :  BSD3

Maintainer  :  s.sichevskij@gmal.com
Stability   :  experimental
Portability :  portable

-}

module Loader.InputFile where

import Survey
import Loader.Parser       ( parseTableFile )
import Loader.Parser.Error ( SCPError )
import Control.Monad.Error ( MonadError, MonadIO, lift )
import Text.Printf         ( printf )
import Text.Scanf

import qualified Survey.WBVR as S

data InputFileType = WBVR deriving (Read, Show)

--parseInputFile :: (MonadError SCPError m, MonadIO m, a ~ String) => InputFileType -> FilePath -> m [(a, [AnyObsData])]
parseInputFile :: (MonadError SCPError m, MonadIO m, a ~ String) => InputFileType -> FilePath -> m [(a, (W S.WBVR, B S.WBVR, V S.WBVR, R S.WBVR))]
parseInputFile WBVR = parseTableFile contentParser postParser
     where
       contentParser = lift $ return $ do
         hd <- string
         sp <- string
         skip
         w  <- double
         b  <- double
         v  <- double
         r  <- double
{--
         let a = AnyObsData ( W S.WBVR $ Just w
                            , B S.WBVR $ Just b
                            , V S.WBVR $ Just v
                            , R S.WBVR $ Just r
                            )
--}
         let a = ( W S.WBVR $ Just w
                 , B S.WBVR $ Just b
                 , V S.WBVR $ Just v
                 , R S.WBVR $ Just r
                 )

--         return (printf "HD : %10s, SP : %8s" hd sp, a)
         return (printf "hd%s_%s" hd sp, a)

       postParser (_, t) = return t